/**
 * Copyright 2014 wasu.com
 *
 *
 * Create on 2015年12月8日 上午11:41:04
 */
package xiaojian.toolkit.bean.mo;

import org.springframework.context.support.AbstractApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import xiaojian.toolkit.bean.bytebean.core.BeanFieldCodec;
import xiaojian.toolkit.util.ByteUtils;

/**
 * @author <a href="mailto:caoxiaojian@wasu.cn">xiaojiancao</a>
 *
 */
public class Main {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		AbstractApplicationContext ctx = new ClassPathXmlApplicationContext(
				"xiaojian/toolkit/bean/mo/byteBeanCodec.xml");

		BeanFieldCodec beanCodec = (BeanFieldCodec) ctx.getBean("byteBeanCodec");
		
		ByteBean bean = new ByteBean();
		bean.setAge(12);
		bean.setName("卧槽日了狗了");
		
		byte[] bytesBody = beanCodec.encode(beanCodec
				.getEncContextFactory().createEncContext(bean, bean.getClass(),
						null));
		
		System.out.println(ByteUtils.bytesAsHexString(bytesBody, 1024));

		System.out.println(beanCodec.decode(beanCodec
				.getDecContextFactory().createDecContext(bytesBody,
						ByteBean.class, null, null)).getValue());
	
	}

}
